package com.ruoyi.web.controller.teaching;


import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.teaching.domain.SysUserFile;
import com.ruoyi.teaching.service.SysUserFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李志鑫
 * @since 2024-06-11
 */
@RestController
@RequestMapping("/sysUserFile")
@Api(tags="th-云盘")
public class SysUserFileController {

    @Autowired
    private SysUserFileService sysUserFileService;
//    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/listFile")
    @ApiOperation("获取云盘文件")
    public AjaxResult listFile(Long fileId, String message)
    {
        return  sysUserFileService.selectFileList(fileId,message);
    }

    @PostMapping ("/insertUpdateFile")
    @ApiOperation("添加修改云盘文件")
    public AjaxResult insertUpdateFile(SysUserFile sysUserFile)
    {
        return  sysUserFileService.insertUpdateFile(sysUserFile);
    }
    @DeleteMapping ("/deleteFile")
    @ApiOperation("删除云盘文件")
    public AjaxResult deleteFile(Long fileId)
    {
        return  sysUserFileService.deleteFile(fileId);
    }

    @GetMapping ("/selectFileSize")
    @ApiOperation("获取云盘容量")
    public AjaxResult selectFileSize()
    {
        Long userId = SecurityUtils.getUserId();
        Double aDouble = sysUserFileService.selectUserSize(userId);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("sizeAll","2");
        hashMap.put("userSize",nf.format(aDouble));

        return  new AjaxResult(HttpStatus.SUCCESS,"成功",hashMap);
    }




}

